package action;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Funding_information;
import dao.Funding_informationDao;

public class Funding_informationServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String page = req.getParameter("page");
		Funding_informationDao fd = new Funding_informationDao();
		ArrayList<Funding_information> funding_information_list = fd
				.getAllFunding_information();
		ArrayList<Funding_information> funding_information_list1 = new ArrayList<Funding_information>();
		ArrayList<Funding_information> funding_information_list2 = new ArrayList<Funding_information>();
		for (int i = 0; i < funding_information_list.size() && i < 12; i++) {
			funding_information_list1.add(funding_information_list.get(i));
			if (i < 6) {
				funding_information_list2.add(funding_information_list.get(i));
			}
		}
		HttpSession session = req.getSession();
		session.setAttribute("funding_information_list",
				funding_information_list);
		session.setAttribute("funding_information_list1",
				funding_information_list1);
		session.setAttribute("funding_information_list2",
				funding_information_list2);

		session.setAttribute("funding_information_total_items",
				funding_information_list.size());
		int num = funding_information_list.size() % 25;
		int funding_information_total_pages = (num == 0 ? funding_information_list
				.size() / 25
				: funding_information_list.size() / 25 + 1);
		session.setAttribute("funding_information_total_pages",
				funding_information_total_pages);
		session.setAttribute("funding_information_current_page", 1);

		resp.sendRedirect("separateFunding_information?page=" + page);
	}
}
